<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a><cite>运维管理</cite></a>
    <a><cite>参数配置</cite></a>
  </div>
</div>

<script type="text/html" template lay-url="agent-admin/settings" lay-done="layui.data.done(d.data)">
  <div class="layui-fluid layui-form">
    <div class="layui-form">
      {{# var settings = d.data }}
      <div class="layui-card">
        <div class="layui-card-header">
          短信设置
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">供应商选择</label>
            <div class="layui-input-inline" style="width: 300px">
              <select name="sms_provider" lay-filter="sms_provider" class="layui-select">
                <option value="ali" selected>阿里云</option>
                <option value="xuncheng">寻程</option>
              </select>
            </div>
          </div>
          <div class="sms_config_panel" id="provider_ali">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">ACCESS_KEY_ID</label>
              <div class="layui-input-inline" style="width: 300px">
                <input type="text" class="layui-input" autocomplete="off"
                       name="ali_access_key_id" value="{{settings.ali_access_key_id || ''}}">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">ACCESS_KEY_SECRET</label>
              <div class="layui-input-inline" style="width: 500px">
                <input type="text" class="layui-input" autocomplete="off"
                       name="ali_access_key_secret" value="{{settings.ali_access_key_secret || ''}}">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">短信签名</label>
              <div class="layui-input-inline">
                <input type="text" class="layui-input" autocomplete="off"
                       name="sms_sign_name" value="{{settings.sms_sign_name || ''}}">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">短信验证码模板</label>
              <div class="layui-input-inline">
                <input type="text" class="layui-input" autocomplete="off"
                       name="verify_code_template" value="{{settings.verify_code_template || ''}}">
              </div>
            </div>
          </div>
          <div class="sms_config_panel" id="provider_xuncheng">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">寻程短信发送AppKey</label>
              <div class="layui-input-inline" style="width: 300px">
                <input type="text" class="layui-input" utocomplete="off"
                       name="xuncheng_sms_appkey" value="{{settings.xuncheng_sms_appkey || ''}}">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">短信验证码模板</label>
              <div class="layui-input-inline">
                <input type="text" class="layui-input" autocomplete="off"
                       name="xuncheng_verify_code_template" value="{{settings.xuncheng_verify_code_template || ''}}">
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-card">
        <div class="layui-card-header">
          寻程数据AppKey设置
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">身份证OCR识别</label>
            <div class="layui-input-inline" style="width: 300px">
              <input type="text" class="layui-input" autocomplete="off"
                     name="xuncheng_ocr_appkey" value="{{settings.xuncheng_ocr_appkey || ''}}">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">身份证实名认证</label>
            <div class="layui-input-inline" style="width: 300px">
              <input type="text" class="layui-input" autocomplete="off"
                     name="xuncheng_realname_appkey" value="{{settings.xuncheng_realname_appkey || ''}}">
            </div>
          </div>

        </div>
      </div>
      <div class="layui-card">
        <div class="layui-card-header">
          禾只参数设置
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label">授权密钥</label>
            <div class="layui-input-inline" style="width: 300px">
              <input type="text" class="layui-input" name="hezhi_key" value="{{settings.hezhi_key || ''}}"
                     autocomplete="off">
            </div>
          </div>
        </div>
      </div>
      <div class="layui-card">
        <div class="layui-card-header">
          交易手续费设置
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">普通订单交易手续费</label>
            <div class="layui-word-aux layui-form-mid">
              {{settings.pay_service_fee_rate || 0}} %
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">转售订单交易手续费</label>
            <div class="layui-word-aux layui-form-mid">
              {{settings.pay_resale_service_fee_rate || 0}} %
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">代理转售手续费率</label>
            <div class="layui-input-inline" style="width: 100px">
              <input type="number" class="layui-input" autocomplete="off"
                     name="pay_resale_agent_fee_rate" value="{{settings.pay_resale_agent_fee_rate || 0}}">
            </div>
            <div class="layui-inline layui-word-aux layui-form-mid">%</div>
          </div>
        </div>
      </div>
      <div class="layui-card">
        <div class="layui-card-header">
          支付渠道设置
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">支付通道</label>
            <div class="layui-input-inline">
              <select name="pay_channel" lay-filter="pay_channel" class="layui-select">
                <option value="sdpay">杉德</option>
                <option value="adapay">汇付天下</option>
                <option value="yeepay">易宝</option>
              </select>
            </div>
          </div>
          <div id="panel_yeepay" class="pay_config_panel">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">代理商户号</label>
              <div class="layui-word-aux layui-form-mid">
                {{settings.pay_merchant_no || ''}}
              </div>
            </div>
          </div>
          <div id="panel_sdpay" class="pay_config_panel">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">商户号</label>
              <div class="layui-word-aux layui-form-mid">
                {{settings.sdpay_merch_no || ''}}
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">商户RSA私钥</label>
              <div class="layui-input-inline" style="width: 600px">
                <textarea readonly class="layui-textarea layui-disabled" autocomplete="off"
                          name="sdpay_rsa_private_key">{{settings.sdpay_rsa_private_key || ''}}
                  </textarea>
              </div>
            </div>
          </div>
          <div id="panel_adapay" class="pay_config_panel" style="display: none">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">APPID</label>
              <div class="layui-word-aux layui-form-mid">
                {{settings.adapay_app_id || ''}}
              </div>
              <!--<div class="layui-input-inline" style="width: 300px">
                <input type="text" class="layui-input" autocomplete="off"
                       name="adapay_app_id" value="{{settings.adapay_app_id || ''}}">
              </div>-->
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">分账账号</label>
              <div class="layui-word-aux layui-form-mid">
                {{settings.adapay_divide_id || ''}}
              </div>
              <!--<div class="layui-input-inline" style="width: 300px">
                <input type="text" class="layui-input" autocomplete="off"
                       name="adapay_divide_id" value="{{settings.adapay_divide_id || ''}}">
              </div>-->
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">API_KEY</label>
              <div class="layui-word-aux layui-form-mid">
                {{settings.adapay_api_key || ''}}
              </div>
              <!--<div class="layui-input-inline" style="width: 300px">
                <input type="text" class="layui-input" autocomplete="off"
                       name="adapay_api_key" value="{{settings.adapay_api_key || ''}}">
              </div>-->
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">商户RSA公钥</label>
              <div class="layui-input-inline" style="width: 600px">
                <textarea readonly class="layui-textarea layui-disabled" autocomplete="off"
                          name="adapay_rsa_public_key">{{settings.adapay_rsa_public_key || ''}}
                  </textarea>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">商户RSA私钥</label>
              <div class="layui-input-inline" style="width: 600px">
                <textarea readonly class="layui-textarea layui-disabled" autocomplete="off"
                          name="adapay_rsa_private_key">{{settings.adapay_rsa_private_key || ''}}
                  </textarea>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-card">
        <div style="margin-bottom: 60px"></div>
        <div class="layui-form-item">
          <div class="layui-footer">
            <div class="layui-input-block">
              <input type="button" lay-submit lay-filter="submit_settings" value="保存"
                     class="layui-btn">
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</script>
<script>
  layui.data.done = function (obj) {
    layui.use([], function () {
      let $ = layui.$
        , form = layui.form
        , admin = layui.admin

      $('select[name="pay_channel"]').val(obj.pay_channel)
      $('select[name="sms_provider"]').val(obj.sms_provider || 'ali')
      form.render()

      form.on('select(pay_channel)', function (d) {
        showPayConfigPanel(d.value)
      })
      form.on('select(sms_provider)', function (d) {
        console.log(d)
        showSmsConfigPanel(d.value)
      })
      let showSmsConfigPanel = function (provider) {
        $('.sms_config_panel').hide()
        $('#provider_' + provider).show()
      }

      let showPayConfigPanel = function (channel) {
        $('.pay_config_panel').hide()
        $('#panel_' + channel).show()
      }
      showSmsConfigPanel(obj.sms_provider || 'ali')
      showPayConfigPanel(obj.pay_channel || 'yeepay')

      // 提交
      form.on('submit(submit_settings)', function (data) {
        let field = data.field;
        admin.post('agent-admin/settings', field, function () {
          layer.msg('保存成功', {
            offset: '15px'
            , icon: 1
            , time: 1000
          });
        });
      });
    });
  }
</script>
